﻿/*
	Tierless Framework
	Test Database
	(Re-)Creation Script
*/

USE [master]
GO

BEGIN TRY
	EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'TierlessTest'
END TRY
BEGIN CATCH
END CATCH

BEGIN TRY
	ALTER DATABASE [TierlessTest] SET  SINGLE_USER WITH ROLLBACK IMMEDIATE
END TRY
BEGIN CATCH
END CATCH

BEGIN TRY
	DROP DATABASE [TierlessTest]
END TRY
BEGIN CATCH
END CATCH

declare @sql nvarchar(4000)
declare @filePath nvarchar(2000)
select  top 1 @filePath = reverse(SubString(reverse(physical_name),CHARINDEX('\', REVERSE(physical_name)), len(physical_name))) from sys.database_files

set @sql = '
CREATE DATABASE [TierlessTest] ON  PRIMARY 
( NAME = N''TierlessTest'', FILENAME = N''' + @FilePath + 'TierlessTest.mdf'' , SIZE = 2048KB , FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N''TierlessTest_log'', FILENAME = N''' + @FilePath + 'TierlessTest_log.ldf'' , SIZE = 1024KB , FILEGROWTH = 10%)'
EXEC(@sql)
GO
ALTER DATABASE [TierlessTest] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [TierlessTest] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [TierlessTest] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [TierlessTest] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [TierlessTest] SET ARITHABORT OFF 
GO
ALTER DATABASE [TierlessTest] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [TierlessTest] SET AUTO_CREATE_STATISTICS ON 
GO
ALTER DATABASE [TierlessTest] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [TierlessTest] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [TierlessTest] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [TierlessTest] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [TierlessTest] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [TierlessTest] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [TierlessTest] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [TierlessTest] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [TierlessTest] SET  DISABLE_BROKER 
GO
ALTER DATABASE [TierlessTest] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [TierlessTest] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [TierlessTest] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [TierlessTest] SET  READ_WRITE 
GO
ALTER DATABASE [TierlessTest] SET RECOVERY SIMPLE 
GO
ALTER DATABASE [TierlessTest] SET  MULTI_USER 
GO
ALTER DATABASE [TierlessTest] SET PAGE_VERIFY CHECKSUM  
GO
USE [TierlessTest]
GO
IF NOT EXISTS (SELECT name FROM sys.filegroups WHERE is_default=1 AND name = N'PRIMARY') ALTER DATABASE [TierlessTest] MODIFY FILEGROUP [PRIMARY] DEFAULT
GO
